import android.content.Context
import com.lq.ecoldchain.base.view.App
import com.lq.ecoldchain.util.PrefsHelper
import java.io.IOException

import okhttp3.Interceptor
import okhttp3.Response

class ResultCheckInterceptor : Interceptor {

    @Throws(IOException::class)
    override fun intercept(chain: Interceptor.Chain): Response {
        val token = App.instance.getSharedPreferences("PrefsDefault", Context.MODE_PRIVATE).getString("token", "")
        val requestBuilder = chain.request()
                .newBuilder()
                .addHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8")
                .addHeader("Accept-Encoding", "gzip, deflate")
                .addHeader("Connection", "keep-alive")
                .addHeader("Connection", "close")
                .addHeader("Accept", "*/*")
        if (!token.isNullOrEmpty()) {
            requestBuilder.addHeader("token", token)
        }
        val d = requestBuilder.build()
        return chain.proceed(d)
    }
}
